package com.example.coreshopapp.task;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.example.coreshopapp.app.Constants;
import com.example.coreshopapp.bean.MemberGoodsReq;
import com.example.coreshopapp.http.AccessNet;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;

public class GetMemberGoodsTask {
    private Handler outHandler;
    private MemberGoodsReq goodsList;

    public void setOutHandler(Handler outHandler) {
        this.outHandler = outHandler;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        //        @SuppressLint("HandlerLeak")
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Message message = outHandler.obtainMessage();
            switch (msg.what) {
                case 9900:
                    message.what = 9900;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
                case 9901:
                    message.what = 9901;
                    message.obj = msg.obj;// info;
                    Log.d("用户登录50010,", msg.obj.toString() + "");
                    outHandler.sendMessage(message);
                    break;
                case 9902:
                    message.what = 9901;
                    message.obj = "操作异常，请重试";// info;
                    outHandler.sendMessage(message);
                    break;
                case 9904:
                    message.what = 9904;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
            }
        }
    };

    private boolean freshNetData() {
        Gson gson = new Gson();
        new Thread(() -> {
            boolean re = AccessNet.postDataNet(mHandler, Constants.urlClass.search_member_goods, 6, gson.toJson(goodsList)); // 调用接口
        }).start();
        return true;
    }

    public Boolean execute(MemberGoodsReq goodsList) {
        this.goodsList = goodsList;
        return freshNetData();
    }
}
